/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.tv.settings.accessories;

import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;

import com.android.tv.settings.R;

/*
 * Provide utilities for Remote & Accessories.
 */
public class AccessoryUtils {
    public static @DrawableRes int getImageIdForDevice(@NonNull BluetoothDevice dev) {
        final BluetoothClass bluetoothClass = dev.getBluetoothClass();
        if (bluetoothClass == null) {
            return R.drawable.ic_bluetooth;
        }

        final int devClass = bluetoothClass.getDeviceClass();

        if (devClass == BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET) {
            return R.drawable.ic_headset_mic;
        } else if (devClass == BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES ||
                devClass == BluetoothClass.Device.AUDIO_VIDEO_LOUDSPEAKER ||
                devClass == BluetoothClass.Device.AUDIO_VIDEO_PORTABLE_AUDIO ||
                devClass == BluetoothClass.Device.AUDIO_VIDEO_HIFI_AUDIO) {
            return R.drawable.ic_headset;
        } else if ((devClass & InputDeviceCriteria.MINOR_DEVICE_CLASS_POINTING) != 0) {
            return R.drawable.ic_mouse;
        } else if ((devClass & InputDeviceCriteria.MINOR_DEVICE_CLASS_JOYSTICK) != 0) {
            return R.drawable.ic_games;
        } else if ((devClass & InputDeviceCriteria.MINOR_DEVICE_CLASS_GAMEPAD) != 0) {
            return R.drawable.ic_games;
        } else if ((devClass & InputDeviceCriteria.MINOR_DEVICE_CLASS_KEYBOARD) != 0) {
            return R.drawable.ic_keyboard;
        }

        // Default for now
        return R.drawable.ic_bluetooth;
    }

    private AccessoryUtils() {
        // do not allow instantiation
    }
}
